﻿using SuperMap.Data;
using SuperMap.Realspace;
using System;
using System.Collections.Generic;
using WeifenLuo.WinFormsUI.Docking;
using Ycjw.PipeLine.Map.Basic.Conditions;
using Ycjw.PipeLine.Map.Basic.SuperMap;

namespace Ycjw.PipeLine.Map.Tools.Conditions
{
    class GJSearcher : ConditionPanel
    {
        private Sunny.UI.UIGroupBox uiGroupBoxgxlx;
        private Sunny.UI.UIGroupBox uiGroupBoxgxcs;
        private Sunny.UI.UILabel uiLabel1;
        private Sunny.UI.UIDoubleUpDown uiDoubleUpDowngxgjMin;
        private Sunny.UI.UILabel uiLabel2;
        private Sunny.UI.UIDoubleUpDown uiDoubleUpDowngxgjMax;
        private Sunny.UI.UICheckBox uiCheckBoxMax;
        private Sunny.UI.UICheckBox uiCheckBoxMin;
        private LayerWithDataListPanel LayerWithDataListPanel;
        public GJSearcher() : base()
        {
            this.ConditionPanelName = "管径查询";
            InitializeComponent();
        }
        protected override void OnLoad(EventArgs e)
        {
            LayerWithDataListPanel = new LayerWithDataListPanel()
            {
                Dock = System.Windows.Forms.DockStyle.Fill
            };
            Scene scene = this.Scene;
            if (scene == null) return;
            LayerWithDataListPanel.Init(scene);
            //LayerWithDataListPanel.LoadToVector();
            var types = new List<DatasetType>()
            {
                DatasetType.Line,
                DatasetType.Line3D ,
                DatasetType.Network,
                DatasetType.Network3D
            };
            LayerWithDataListPanel.LoadTo(types);
            this.uiGroupBoxgxlx.Controls.Add(LayerWithDataListPanel);
            uiGroupBoxgxlx.Width = this.Width / 2;
            /*
             Scene scene = null;
             if (BaseConditions.ContainsKey("Scene"))
             {
                 scene = BaseConditions["Scene"] as Scene;
             }
             if (scene == null) return;
             var lyrInScene = scene.Layers;
             this.groupBoxgjcx.Controls.Clear();
             var positionTop = 20;
             foreach (Layer3D lyr in lyrInScene)
             {
                 RadioButton rb = new RadioButton();
                 rb.Text = lyr.Caption;
                 rb.Name = lyr.Name;
                 rb.AutoSize = true;
                 rb.Location = new System.Drawing.Point(10, positionTop);
                 positionTop += 24;
                 this.groupBoxgjcx.Controls.Add(rb);
             }
           */
        }

        public override bool ConditionValid()
        {
            var dataset = LayerWithDataListPanel.SelectLayer3DDataset;
            if (dataset == null)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层不是矢量图层");
                return false;
            }

            return base.ConditionValid();
        }
        public override object Do(DockPanel dockPanel = null)
        {
            var dataset = LayerWithDataListPanel.SelectLayer3DDataset;
            if (dataset == null)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层不是矢量图层");
                return null;
            }

            var dataSetVector = dataset.Dataset as SuperMap.Data.DatasetVector;
            bool hasGJField = false;
            for (int i = 0; i < dataSetVector.FieldInfos.Count; i++)
            {
                if (dataSetVector.FieldInfos[i].Name == "管径")
                {
                    hasGJField = true;
                    break;
                }
            }
            if (!hasGJField)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层没有管径信息");
                return null;
            }
            DatasetVectorEx dvEx = new DatasetVectorEx(dataset.Name)
            {
                DatasetVector = dataSetVector
            };
            var sql = "SmID > 0 ";
            if (uiCheckBoxMin.Checked)
            {
                sql += " And 管径 >= " + this.uiDoubleUpDowngxgjMin.Value;
            }
            if (uiCheckBoxMax.Checked)
            {
                sql += " And 管径 <= " + this.uiDoubleUpDowngxgjMax.Value;
            }
            var dt = dvEx.Query(sql);
            dt.TableName = dataset.Caption;
            return dt;

            //this.ShowResult(dat, dockPanel, DockState.DockBottom, "按管径查询-执行结果");
            //base.Do(dockPanel);
        }

        private void InitializeComponent()
        {
            this.uiGroupBoxgxlx = new Sunny.UI.UIGroupBox();
            this.uiGroupBoxgxcs = new Sunny.UI.UIGroupBox();
            this.uiCheckBoxMax = new Sunny.UI.UICheckBox();
            this.uiCheckBoxMin = new Sunny.UI.UICheckBox();
            this.uiLabel2 = new Sunny.UI.UILabel();
            this.uiLabel1 = new Sunny.UI.UILabel();
            this.uiDoubleUpDowngxgjMax = new Sunny.UI.UIDoubleUpDown();
            this.uiDoubleUpDowngxgjMin = new Sunny.UI.UIDoubleUpDown();
            this.uiGroupBoxgxcs.SuspendLayout();
            this.SuspendLayout();
            // 
            // uiGroupBoxgxlx
            // 
            this.uiGroupBoxgxlx.Dock = System.Windows.Forms.DockStyle.Left;
            this.uiGroupBoxgxlx.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBoxgxlx.Location = new System.Drawing.Point(0, 0);
            this.uiGroupBoxgxlx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBoxgxlx.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBoxgxlx.Name = "uiGroupBoxgxlx";
            this.uiGroupBoxgxlx.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBoxgxlx.Size = new System.Drawing.Size(223, 316);
            this.uiGroupBoxgxlx.TabIndex = 0;
            this.uiGroupBoxgxlx.Text = "管线类型";
            // 
            // uiGroupBoxgxcs
            // 
            this.uiGroupBoxgxcs.Controls.Add(this.uiCheckBoxMax);
            this.uiGroupBoxgxcs.Controls.Add(this.uiCheckBoxMin);
            this.uiGroupBoxgxcs.Controls.Add(this.uiLabel2);
            this.uiGroupBoxgxcs.Controls.Add(this.uiLabel1);
            this.uiGroupBoxgxcs.Controls.Add(this.uiDoubleUpDowngxgjMax);
            this.uiGroupBoxgxcs.Controls.Add(this.uiDoubleUpDowngxgjMin);
            this.uiGroupBoxgxcs.Dock = System.Windows.Forms.DockStyle.Fill;
            this.uiGroupBoxgxcs.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBoxgxcs.Location = new System.Drawing.Point(223, 0);
            this.uiGroupBoxgxcs.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBoxgxcs.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBoxgxcs.Name = "uiGroupBoxgxcs";
            this.uiGroupBoxgxcs.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBoxgxcs.Size = new System.Drawing.Size(234, 316);
            this.uiGroupBoxgxcs.TabIndex = 1;
            this.uiGroupBoxgxcs.Text = "管线管径(毫米mm)";
            // 
            // uiCheckBoxMax
            // 
            this.uiCheckBoxMax.BackColor = System.Drawing.Color.Transparent;
            this.uiCheckBoxMax.Cursor = System.Windows.Forms.Cursors.Hand;
            this.uiCheckBoxMax.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiCheckBoxMax.Location = new System.Drawing.Point(7, 137);
            this.uiCheckBoxMax.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiCheckBoxMax.Name = "uiCheckBoxMax";
            this.uiCheckBoxMax.Padding = new System.Windows.Forms.Padding(22, 0, 0, 0);
            this.uiCheckBoxMax.Size = new System.Drawing.Size(32, 29);
            this.uiCheckBoxMax.TabIndex = 6;
            // 
            // uiCheckBoxMin
            // 
            this.uiCheckBoxMin.BackColor = System.Drawing.Color.Transparent;
            this.uiCheckBoxMin.Checked = true;
            this.uiCheckBoxMin.Cursor = System.Windows.Forms.Cursors.Hand;
            this.uiCheckBoxMin.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiCheckBoxMin.Location = new System.Drawing.Point(7, 60);
            this.uiCheckBoxMin.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiCheckBoxMin.Name = "uiCheckBoxMin";
            this.uiCheckBoxMin.Padding = new System.Windows.Forms.Padding(22, 0, 0, 0);
            this.uiCheckBoxMin.Size = new System.Drawing.Size(32, 29);
            this.uiCheckBoxMin.TabIndex = 5;
            // 
            // uiLabel2
            // 
            this.uiLabel2.BackColor = System.Drawing.Color.Transparent;
            this.uiLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiLabel2.Location = new System.Drawing.Point(38, 138);
            this.uiLabel2.Name = "uiLabel2";
            this.uiLabel2.Size = new System.Drawing.Size(58, 23);
            this.uiLabel2.TabIndex = 4;
            this.uiLabel2.Text = "最大：";
            this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiLabel1
            // 
            this.uiLabel1.BackColor = System.Drawing.Color.Transparent;
            this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiLabel1.Location = new System.Drawing.Point(38, 61);
            this.uiLabel1.Name = "uiLabel1";
            this.uiLabel1.Size = new System.Drawing.Size(58, 23);
            this.uiLabel1.TabIndex = 1;
            this.uiLabel1.Text = "最小：";
            this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiDoubleUpDowngxgjMax
            // 
            this.uiDoubleUpDowngxgjMax.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiDoubleUpDowngxgjMax.Location = new System.Drawing.Point(103, 135);
            this.uiDoubleUpDowngxgjMax.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiDoubleUpDowngxgjMax.MinimumSize = new System.Drawing.Size(100, 0);
            this.uiDoubleUpDowngxgjMax.Name = "uiDoubleUpDowngxgjMax";
            this.uiDoubleUpDowngxgjMax.Size = new System.Drawing.Size(121, 29);
            this.uiDoubleUpDowngxgjMax.Step = 1D;
            this.uiDoubleUpDowngxgjMax.TabIndex = 3;
            this.uiDoubleUpDowngxgjMax.Text = "uiDoubleUpDown1";
            this.uiDoubleUpDowngxgjMax.Value = 0D;
            // 
            // uiDoubleUpDowngxgjMin
            // 
            this.uiDoubleUpDowngxgjMin.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiDoubleUpDowngxgjMin.Location = new System.Drawing.Point(103, 58);
            this.uiDoubleUpDowngxgjMin.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiDoubleUpDowngxgjMin.MinimumSize = new System.Drawing.Size(100, 0);
            this.uiDoubleUpDowngxgjMin.Name = "uiDoubleUpDowngxgjMin";
            this.uiDoubleUpDowngxgjMin.Size = new System.Drawing.Size(121, 29);
            this.uiDoubleUpDowngxgjMin.Step = 1D;
            this.uiDoubleUpDowngxgjMin.TabIndex = 0;
            this.uiDoubleUpDowngxgjMin.Text = "uiDoubleUpDown1";
            this.uiDoubleUpDowngxgjMin.Value = 0D;
            // 
            // GJSearcher
            // 
            this.Controls.Add(this.uiGroupBoxgxcs);
            this.Controls.Add(this.uiGroupBoxgxlx);
            this.Name = "GJSearcher";
            this.Size = new System.Drawing.Size(457, 316);
            this.uiGroupBoxgxcs.ResumeLayout(false);
            this.ResumeLayout(false);

        }
    }
}
